//
//  UIBarButtonItem+Extension.swift
//  SmartEyeForDoctor
//
//  Created by QDSG on 2021/5/8.
//

import UIKit

extension UIBarButtonItem {
    convenience init(imageName: String, target: Any?, action: Selector) {
        let btn = UIButton(type: .custom)
        btn.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        btn.setImage(UIImage(named: imageName), for: .normal)
        btn.setImage(UIImage(named: imageName), for: .highlighted)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        self.init(customView: btn)
    }
    
    convenience init(title: String,
                     target: Any?,
                     action: Selector,
                     titleFont: UIFont = UIFont.medium(14),
                     normalColor: UIColor = UIColor(hex: "#40B689"),
                     highlightedColor: UIColor = UIColor(hex: "#40B689").withAlphaComponent(0.8)) {
        let btn = UIButton(type: .custom)
        btn.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        btn.titleLabel?.font = titleFont
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(normalColor, for: .normal)
        btn.setTitleColor(highlightedColor, for: .highlighted)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        self.init(customView: btn)
    }
}
